<template>
  <div>
    <el-dialog title="批量修改" :visible.sync="dialogVisible" width="40%">
      <div>
        <el-row>
          <el-col :span="6">
              <div style="text-align:right;padding:0.5rem;">状态：</div>
          </el-col>
          <el-col :span="10">
            <el-select v-model="status" placeholder="请选择">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"
                :disabled="item.disabled">
              </el-option>
            </el-select>
          </el-col>
        </el-row>
      </div>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="doupdate">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import _ from 'lodash'
  export default {
    data() {
      return {
        dialogVisible: false,
        data: {},
        status:0,
        options: [{
          value: 0,
          label: '未处理'
        }, {
          value: 1,
          label: '不符合要求',
        }, {
          value: 2,
          label: '已转发'
        }, {
          value: 3,
          label: '已通知'
        }, {
          value: 4,
          label: '已笔试'
        }, {
          value: 5,
          label: '一面通过'
        }, {
          value: 6,
          label: '一面未通过',
        }, {
          value: 7,
          label: '二面通过'
        }, {
          value: 8,
          label: '二面未通过'
        }, {
          value: 9,
          label: '已录用'
        }, {
          value: 10,
          label: '已过期'
        }]
      }
    },
    methods: {
      init(data) {
        this.dialogVisible = true
        this.data = data
      },
      //向服务器发出修改请求
      doupdate() {
        let status = this.checkStatus(this.status)
        let ids = _.map(this.data, "resumeId")
        this.$http({
          url: `${this.$http.adornUrl('/resume/batchUpdate')}`,
          method: 'post',
          data: this.$http.adornData({'ids':ids,'status':status}, false)
        }).then(({
          data
        }) => {
          if (data['code'] == 0) {
            this.dialogVisible = false
            this.$message({
              message: '更新成功',
              type: 'success'
            });
            this.$emit('fnc')
          } else {
            this.$message({
              message: '更新错误',
              type: 'error'
            });
          }
        })
      },
      //解决将字符串作为status的问题
      checkStatus(status){
          this.options.forEach(item=>{
              if(status==item.label){
                  status=item.value
              }
          })
          return status
      },
    }
  }

</script>
